AC_INIT([gdnsd-plugin-weighted],[0.02],[me@knyar.net],[gdnsd-plugin-weighted],[http://gdnsd-plugin-weighted.googlecode.com])
AC_PREREQ([2.68])
AC_CONFIG_AUX_DIR([acaux])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([1.11.1 dist-xz foreign])

AC_PROG_CC
AC_PROG_CC_C99
if test "x$ac_cv_prog_cc_c99" = xno; then
    AC_MSG_ERROR([Your compiler lacks sufficient C99 support])
fi
AC_USE_SYSTEM_EXTENSIONS

dnl If no --prefix given, attempt to default to the prefix
dnl   gdnsd is found at in $PATH
AC_PREFIX_PROGRAM([gdnsd])

AC_DISABLE_STATIC
LT_INIT([disable-fast-install])
LT_PREREQ([2.4])
AC_SUBST([LIBTOOL_DEPS])

ACX_PTHREAD(,AC_MSG_ERROR([POSIX threads support is required]))

LIBS="$PTHREAD_LIBS $LIBS"
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
CC="$PTHREAD_CC"

dnl Check for perl 5.8.1+ (needed for doc regeneration)
AC_REQUIRE_AUX_FILE([noperl])
AC_PATH_PROG([PERL],[perl])
AX_PROG_PERL_VERSION([5.8.1],[
    HAVE_PERL=1
    AC_PATH_PROG([POD2MAN],[pod2man])
],[
    AC_MSG_WARN([Cannot edit the documentation source without perl 5.8.1+])
    PERL=$am_aux_dir/noperl
    POD2MAN=$am_aux_dir/noperl
    AC_SUBST([POD2MAN])
])

dnl Check for --enable-developer
developer=no
AC_ARG_ENABLE(developer,
    [  --enable-developer      Turn on gcc developer warnings, debugging, etc (default=no)],
    [if test "x$enable_developer" = xyes; then developer=yes; fi])

dnl If developer, set -g and a ton of warnings.  Otherwise, set -DNDEBUG
if test "x$developer" != xno; then
  if test x"$ac_cv_prog_cc_g" = xyes; then
    CFLAGS="${CFLAGS} -g -Wall -W"
  fi
  AC_DEFINE_UNQUOTED(EV_VERIFY, 3, [libev verification checks])
else
  CPPFLAGS="-DNDEBUG ${CPPFLAGS}"
  AC_DEFINE_UNQUOTED(EV_VERIFY, 0, [libev verification checks])
fi

dnl Allow the user to tell us where to find the gdnsd include files are at
if test "x$prefix" != xNONE; then
    our_pfx=$prefix
else
    our_pfx=$ac_default_prefix
fi
AC_ARG_WITH([gdnsd-prefix],[
  --with-gdnsd-prefix=/x/y     If you are installing this plugin to a different
                          directory than gdnsd was installed to, specify
                          the installation prefix of the original gdnsd
                          installation here, so that we can locate the
                          installed header files.  If not specified, defaults
                          to assuming the same prefix this plugin is being
                          installed to.],
    [],
    [withval=$our_pfx]
)
GDNSD_PFX=$withval
AC_SUBST(GDNSD_PFX)

dnl Now check that gdnsd-plugin.h is actually working
xCPPFLAGS=$CPPFLAGS
CPPFLAGS="$CPPFLAGS -I${GDNSD_PFX}/include -DGDNSD_PLUGIN_NAME=foobar"
AC_CHECK_HEADER([gdnsd-plugin.h],,AC_MSG_ERROR([gdnsd-plugin.h could not be found/compiled]))
CPPFLAGS=$xCPPFLAGS

dnl Output generation
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([
  Makefile
  src/Makefile
  docs/Makefile
])
AC_OUTPUT
